
export const SetOpenKeys = (value: (string | number)[]) => {
  localStorage.setItem("OPEN_KEYS", JSON.stringify(value))
}

export const SetSelectedKeys = (value: string[]) => {
  localStorage.setItem("SELECTED_KEYS",JSON.stringify(value))
}

export const GetOpenKeys = () => {
  let value = localStorage.getItem("OPEN_KEYS")
  return JSON.parse(String(value))
}

export const GetSelectedKeys = () => {
  let value = localStorage.getItem("SELECTED_KEYS")
  return JSON.parse(String(value))
}

export const GetToken = () => {
  return localStorage.getItem("ANTDV_TOKEN")
}

export const SetToken = (value: string | null | undefined) => {
  return localStorage.setItem("ANTDV_TOKEN", String(value))
}

export const GetLanguage = () => {
  return localStorage.getItem("lang") || "zh-cn"
}

export const SetLanguage = (value: string | null | undefined) => {
  return localStorage.setItem("lang", String(value))
}

export const Debounce = (func: () => void, delay: number) =>  {
    let timeoutId: ReturnType<typeof setTimeout> | null = null
    return () => {
      if (timeoutId) {
        clearTimeout(timeoutId)
      }
      timeoutId = setTimeout(() => {
        func();
        timeoutId = null;
      }, delay)
    }
}

export const LoadStaticPath = (path:string) => {
  let url = ""
  if(path[0] != '@') {
    const env = import.meta.env
    url = env.VITE_APP_URL.slice(0, -1);
  }else {
    url = ""
  }
  return url + path
}

